<!DOCTYPE html> 
<!--
 Copyright (c) 2014, 2017 AIT, fortiss GmbH
  
 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License 2.0 which is available at
 http://www.eclipse.org/legal/epl-2.0.

 SPDX-License-Identifier: EPL-2.0
 
 Contributors:
   Filip Andren, Monika Wenger, Jose Cabral
     - initial API and implementation and/or initial documentation
-->

<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Modbus</title>
	<link rel="stylesheet" type="text/css" href="../help.css">
</head>

<body>
<h1 id="topOfPage">Modbus</h1>
<h2>Installation Instructions</h2>
<p>The Modbus com interface need the <a href="http://libmodbus.org/" target="_blank">libmodbus</a> library to work. Follow the steps below to set up your environment before compiling FORTE.</p>

<ol>
	<li>libmodbus files should be placed in the following folder structure:
		<ul>
			<li><span class="folderLocation">[ibmodbushome]/include/modbus</span>: include files</li>
			<li><span class="fileLocation">[libmodbushome]/lib: libmodbus.lib</span> (windows) or <span class="fileLocation">libmodbus.so</span> (posix)</li>
		</ul>
	</li>
	<li>When configuring FORTE project with CMake choose <span class="specificText">[ibmodbushome]</span> as <span class="specificText">FORTE_COM_MODBUS_LIB_DIR</span></li>
	<li><span class="fileLocation">forte.exe</span> must be able to find the dynamic libmodbus library after build. Therefore copy <span class="fileLocation">libmodbus.dll/so</span> to folder with <span class="fileLocation">forte.exe</span> or add <span class="fileLocation">libmodbus.dll/so</span> to library include path.</li>
</ol>

<h2>Parameters</h2>
<h3>Modbus Client (TCP)</h3>
<p>Usage of the Modbus Client (TCP):</p>
<div class="code">modbus[(protocol:)ip:port:pollFreqency:functionCode:(slaveId):readAddresses:sendAddresses(:responseTimeout:byteTimeout)]</div>

<ul>
	<li><span class="inlineTitle">protocol</span>: tcp (tcp is default)</li>
	<li><span class="inlineTitle">ip</span>: address of Modbus server, e.g. 127.0.0.1 </li>
	<li><span class="inlineTitle">port</span>: preferably above 1024, default is 502</li>
	<li><span class="inlineTitle">pollFrequency</span>: polling frequency in milliseconds</li>
	<li><span class="inlineTitle">functionCode</span>: an integer between 1 and 4 
		<ul>
			<li>1 = Read Coils</li>
			<li>2 = Read Discrete Inputs</li>
			<li>3 = Read Holding Registers</li>
			<li>4 = Read Input Register</li>
		</ul>
	</li>
	<li><span class="inlineTitle">slaveId</span> (optional): the slave id used by the modbus server (0xFF is standard); this is in principle an optional parameter but some modbus devices - e.g. Siemens SENTRON PAC power measurement devices - need this parameter in order to establish a connection</li>
	<li><span class="inlineTitle">readAddresses</span>: addresses can be specified between 0-65535 more than one address (max 100) can be specified using
		<ul>
			<li>comma for separate addresses 0,2,65500</li>
			<li>dots for interval 5..10</li>
			<li>combination 0,5..10,2,65500</li>
		</ul>
	</li>
	<li><span class="inlineTitle">sendAddresses</span>: addresses can be specified between 0-65535 if data is only read sendAddresses should be left empty more than one address (max 100) can be specified using
		<ul>
			<li>comma for separate addresses 0,2,65500</li>
			<li>dots for interval 5..10</li>
			<li>combination 0,5..10,2,65500</li>
		</ul>
	</li>
	<li><span class="inlineTitle">responseTimeout</span> (optional): timeout in milliseconds to wait for a response (500ms is default)</li>
	<li><span class="inlineTitle">byteTimeout</span> (optional): timeout in milliseconds between two consecutive bytes (500ms is default)</li>
</ul>

<p>Example:</p>
<div class="code">modbus[127.0.0.1:502:2000:3:1:0..3]</div>

<h3>Modbus Client (RTU)</h3>
<p>Usage of the Modbus Client (RTU):</p>
<div class="code">modbus[protocol:device:baudRate:parity:dataBit:stopBit:pollFreqency:functionCode:(slaveId):readAddresses:sendAddresses(:responseTimeout:byteTimeout)]</div>

<p>Parameter meaning:</p>
<ul>
	<li><span class="inlineTitle">protocol</span>: rtu</li>
	<li><span class="inlineTitle">device</span>: serial device, e.g., /dev/ttyS0</li>
	<li><span class="inlineTitle">baudRate</span>: baud rate</li>
	<li><span class="inlineTitle">parity</span>: N for none, E for even, O for odd</li>
	<li><span class="inlineTitle">dataBit</span>: number of data bits </li>
	<li><span class="inlineTitle">stopBit</span>: number of stop bits </li>
	<li><span class="inlineTitle">pollFrequency</span>: polling frequency in milliseconds</li>
	<li><span class="inlineTitle">functionCode</span>: an integer between 1 and 4, whereas 
		<ul>
			<li>1 = Read Coils</li>
			<li>2 = Read Discrete Inputs</li>
			<li>3 = Read Holding Registers</li>
			<li>4 = Read Input Register</li>
		</ul>
	</li>
	<li><span class="inlineTitle">slaveId</span> (optional): the slave id used by the modbus server (0xFF is standard); this is in principle an optional parameter but some modbus devices - e.g. Siemens SENTRON PAC power measurement devices - need this parameter in order to establish a connection</li>
	<li><span class="inlineTitle">readAddresses</span>: addresses can be specified between 0-65535. More than one address (max 100) can be specified using 
		<ul>
			<li>comma for separate addresses 0,2,65500 </li>
			<li>dots for interval 5..10 </li>
			<li>combination 0,5..10,2,65500 </li>
		</ul>
	</li>
	<li><span class="inlineTitle">sendAddresses</span>: addresses can be specified between 0-65535. More than one address (max 100) can be specified using 
		<ul>
			<li>comma for separate addresses 0,2,65500 </li>
			<li>dots for interval 5..10 </li>
			<li>combination 0,5..10,2,65500 </li>
		</ul>
	<li><span class="inlineTitle">responseTimeout</span> (optional): timeout in milliseconds to wait for a response (500ms is default) </li>
	<li><span class="inlineTitle">byteTimeout</span> (optional): timeout in milliseconds between two consecutive bytes (500ms is default) </li>
</ul>

<p>Example:</p>
<div class="code">modbus[rtu:/dev/ttyS0:19200:E:8:1:2000:3:247:6142,6132,6137:64025..64025,63995..63995]</div>

<h1>Where to go from here?</h1>

<p>Go back to Protocols index:</p>

<p><a href="../../html/communication/communicationIndex.html">Communication Index</a></p>

<p>If you want to go back to the Start Here page, we leave you here a fast access</p>

<p><a href="../../html/startHere/startHere.html">Start Here page</a></p>

<p class="goToTop">Or <a href="#topOfPage">Go to top</a></p>

</body>
</html>